package com.wl.api.service.system.impl;

import java.util.Objects;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.wl.api.dto.system.SecurityUserDTO;
import com.wl.api.mapper.system.SecurityUserRoleMapper;
import com.wl.api.model.system.SecurityUserRole;
import com.wl.api.service.system.ISecurityUserRoleService;

/**
 *
 * SecurityUserRole 表数据服务层接口实现类
 *
 */
@Service
public class SecurityUserRoleServiceImpl extends ServiceImpl<SecurityUserRoleMapper, SecurityUserRole> implements ISecurityUserRoleService {

	@Transactional
	public void saveOrUpdateUserRole(SecurityUserDTO param) {
		Assert.isTrue(param!= null && param.getId() != null && param.getRoleId() != null);
		SecurityUserRole  data = selectOne(new EntityWrapper<SecurityUserRole>().where("user_id={0}", param.getId())) ;
		if(Objects.isNull(data)) {
			insert(SecurityUserRole.builder().userId(param.getId()).roleId(param.getRoleId()).build());
		}else {
			updateById(SecurityUserRole.builder().roleId(param.getRoleId()).id(data.getId()).build());
		}
	}

}